package cn.school.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.school.entity.Subject;
import cn.school.service.SubjectService;
import cn.school.util.StringKit;

/**
 * Servlet implementation class SubjectServlet
 */
@WebServlet("/subjectServlet")
public class SubjectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public SubjectServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	SubjectService service = new SubjectService();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int pageNo = StringKit.toInt(request.getParameter("pageNo"), 1);
		List<Subject> list = service.search(pageNo);
		int total = service.total();
		// PrintWriter out = response.getWriter();
		// request,session,application
		request.setAttribute("list", list);
		request.setAttribute("total", total);
		request.setAttribute("pageNo", pageNo);
		request.getRequestDispatcher("/WEB-INF/jsp/subjects.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
